import moment from 'moment'
import { nullDisplay } from '../utils'

export default {
  props: {
    value: Array,
    row: Object,
    options: Object
  },
  render(h) {
    if (!this.value.length) {
      return nullDisplay(h, this.options)
    }
    var _opt = Object.assign(
      {
        split: ' - ',
        format: 'YYYY-MM-DD HH:mm:ss'
      },
      this.options
    )
    var range = this.value.map(item => {
      if (!item) {
        return nullDisplay(h, this.options)
      } else {
        return moment(item * 1000).format(_opt.format)
      }
    })
    if (_opt.split) {
      range = range.reduce((r, a, index) => {
        console.log('----', r, a)
        return r.concat(a, index < range.length - 1 && _opt.split)
      }, [])
    }
    return h('div', {}, range)
  }
}
